<script>
    // 使用setTimeout实现setInterval
    function mlSetTimout(fn, delay) {
        let timer = null;
        let interval = () => {
            fn();
            timer = setTimeout(interval, delay)
        }
        setTimeout(interval, delay)

        return {
            cancel() {
                clearTimeout(timer)
            }
        }
    }

    // mlSetTimout(() => console.log(888), 1000);

    let { cancel } = mlSetTimout(() => console.log(888), 1000);
    setTimeout(() => {
        cancel();
    }, 5000);
</script>